﻿using System;
using System.Collections.Generic;
using System.Data;
using System.Data.Common;
using System.Linq;
using System.Text;

namespace Wjtour.BLL
{
    public class articleattachment_bll : base_dll
    {
        public Wjtour.Domain.articleattachment Load(int id)
        {
            string sql = "select * from articleattachment where id=" + id;
            return DbAccess.GetObjects<Wjtour.Domain.articleattachment>(sql).FirstOrDefault();
        }

        public bool Save(Wjtour.Domain.articleattachment entity)
        {
            string sql = "";

            DbCommand cmd = DbAccess.CreateCommand();

            if (entity.id > 0)
            {
                sql = @"UPDATE [articleattachment] SET 
                [path] = @path,
                [articleid] = @articleid,
                [articletypeid] = @articletypeid,
                [addtime] = @addtime
                 WHERE id=@id";
                DbAccess.AddInParameter(cmd, "@id", DbType.Int32, entity.id);

            }
            else
            {
                sql = @"INSERT INTO [articleattachment]( 
                [path],[articleid],[articletypeid],[addtime])VALUES(
                @path,@articleid,@articletypeid,@addtime)";
            }
            DbAccess.AddInParameter(cmd, "@path", DbType.String, entity.path);
            DbAccess.AddInParameter(cmd, "@articleid", DbType.Int32, entity.articleid);
            DbAccess.AddInParameter(cmd, "@articletypeid", DbType.Int32, entity.articletypeid);
            DbAccess.AddInParameter(cmd, "@addtime", DbType.DateTime, entity.addtime);
            cmd.CommandText = sql;
            cmd.CommandType = System.Data.CommandType.Text;
            return DbAccess.ExecuteNonQuery(cmd) > 0;
        }


        public int BatchDelete(string ids)
        {
            string sql = "delete from articleattachment where id in(" + ids + ")";
            return DbAccess.ExecuteNonQuery(sql);
        }
    }
}
